package cn.com.dpc.setActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import cn.com.dpc.AboutActivity;
import cn.com.dpc.AddActivity;
import cn.com.dpc.R;

public class UpdateActivity extends Activity {
	private List<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
	private ListView set01;
	private String lv_items[] = { "检查更新", "意见反馈", "官方网站" };

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.update);

		set01 = (ListView) findViewById(R.id.update);

		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("name", lv_items[0]);
		listItem.add(map);
		HashMap<String, Object> map1 = new HashMap<String, Object>();
		map1.put("name", lv_items[1]);
		listItem.add(map1);
		HashMap<String, Object> map2 = new HashMap<String, Object>();
		map2.put("name", lv_items[2]);
		listItem.add(map2);

		SimpleAdapter sa = new SimpleAdapter(UpdateActivity.this, listItem,
				R.layout.listviewupdate, new String[] { "name", },
				new int[] { R.id.itemTitle });
		set01.setAdapter(sa);

		// set01.setAdapter(new ArrayAdapter<String>(this,
		// android.R.layout.simple_list_item_multiple_choice, lv_items));
		// set01.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

		set01.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				String clickStr = lv_items[arg2];
				Log.v("str: ", clickStr);
				if (clickStr.equals(lv_items[1])) {
					Intent emailIntent = new Intent(
							android.content.Intent.ACTION_SEND);
					// 设置文本格式
					emailIntent.setType("text/plain");
					// 设置对方邮件地址
					emailIntent
							.putExtra(android.content.Intent.EXTRA_EMAIL, "");
					// 设置标题内容
					emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
							"咨询");
					// 设置邮件文本内容
					emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
							"怎么用？");
					startActivity(Intent.createChooser(emailIntent,
							"Choose Email Client"));

				}
			}
		}); // End of Listener

		// 隐藏按钮
		ImageButton editButton = (ImageButton) findViewById(R.id.edit_button);
		editButton.setVisibility(View.INVISIBLE);
		ImageButton backButton = (ImageButton) findViewById(R.id.back_button);
		backButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				UpdateActivity.this.finish();
			}
		});
		TextView titleText = (TextView) findViewById(R.id.myTitle);
		titleText.setText("帮助更新");
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			UpdateActivity.this.finish();
			return false;
		}
		return false;
	}
}
